import components from './components'
import methods from './methods'
import directives from './directives'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { App } from 'vue'

export default {
  install(app: App<Element>) {
    // 全局方法挂载
    Object.keys(methods).forEach(item => {
      // keyof遍历类型
      app.config.globalProperties[item] = methods[item as keyof typeof methods]
    })
    // 全局组件
    Object.keys(components).forEach((element: string) => {
      // keyof遍历类型
      app.component(element, components[element as keyof typeof components])
    })
    // 全局指令
    Object.keys(directives).forEach((item: string) => {
      // keyof遍历类型
      app.directive(item, directives[item as keyof typeof directives])
    })
    // 字体图标
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
  }
}
